<?php
class imgcache
{
	function getBrickHash($bx, $by)
	{
		return CACHE_DIR.'/brick'.($bx*1000+$by).'.jpg';
	}
	
	function deleteMapBrick($bx, $by)
	{
		$hash = self::getBrickHash($bx, $by);
		if (file_exists($hash))
		{
			unlink($hash);
		}
	}
	
	function putMapBrick($bx, $by, $im, $quality=60)
	{
		if (!$im) return false;
		imagejpeg($im, self::getBrickHash($bx, $by), 55);
	}

	function getMapBrick($bx, $by)
	{
		$hash = self::getBrickHash($bx, $by);
		if (file_exists($hash))
			return file_get_contents($hash);
	}
}